﻿using Asp.Versioning;
using FlyingEye.DeviceMaintenanceServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace FlyingEye.Controllers
{
    [Route("api/device-ops-service/v{version:apiVersion}/maintenance-records")]
    [ApiVersion("1.0")]
    [ControllerName("MaintenanceRecord")]
    [Authorize]
    public class MaintenanceRecordController : DefaultController
    {
        private readonly MaintenanceRecordService _maintenanceRecordService;

        private readonly DevicePartCheckedResultService _devicePartCheckedResultService;

        public MaintenanceRecordController(
            MaintenanceRecordService maintenanceRecordService,
            DevicePartCheckedResultService devicePartCheckedResultService)
        {
            _maintenanceRecordService = maintenanceRecordService;
            _devicePartCheckedResultService = devicePartCheckedResultService;
        }

        [HttpGet("{id}")]
        public async Task<ActionResult<MaintenanceRecordResponse>> GetAsync(Guid id)
        {
            return await GetInvokeAsync(async () =>
            {
                return await _maintenanceRecordService.GetAsync(id);
            });
        }

        [HttpGet("{id}/checked-results")]
        public async Task<ActionResult<List<DevicePartCheckedResultResponse>>> GetCheckedResultsAsync(Guid id)
        {
            return await GetInvokeAsync(async () =>
            {
                return await _devicePartCheckedResultService.GetListByRecordAsync(id);
            });
        }
    }
}
